/**
 * Created by bilee on 17/1/22.
 */
layui.define(['jquery'], function (exports) {
    var $ = layui.jquery, time = 120,serverUrl="http://localhost/bnpt/Api/Portal/";
    var obj = {
        is_phone: function (tel) {
            var jundge = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0-9]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
            if (tel.length != 11 || !tel.match(jundge)) {
                return false;
            }
            return true;
        },
        //get phone code
        get_code: function (tel, token, url, el_obj) {
            if (obj.is_phone(tel)) {
                $(".pc_login_tip").hide(200);
                if (120 === time) {
                    //sending
                    $(el_obj).text("发送中...");
                    $.getJSON(url + tel + '/r/' + token, function (result) {
                        if (200 === result.retCode) {
                            //重新发送事件
                            $(el_obj).text("重新发送(" + time + ")");
                            var settime = setInterval(function () {
                                time = time - 1;
                                $(el_obj).text("重新发送(" + time + ")");
                                //停止倒计时
                                if (time <= 0) {
                                    clearInterval(settime);
                                    $(el_obj).text("重新发送");
                                    //还原倒计时
                                    time = 120;
                                }
                            }, 1000)
                        } else {
                            $(".pc_login_tip").show(200);
                            $("#pc_login_tip").text(result.retDesc);
                            $(el_obj).text("获取验证码");
                        }
                    });
                    return true;
                } else {
                    return true;
                }

            } else {
                return false;
            }
        },
        //获取建议地址
        get_order_price: function (startLat,startLng,endLat,endLng,cityid) {
            $.getJSON(serverUrl+'getOrderAmount?startLat='+startLat+'&startLng='+startLng+'&endLat='+endLat+'&endLng='+endLng,function(ret){
                console.log(ret);
            });
        }
    }

    exports('base', obj);
});
